<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['bargain_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  查询表单开始  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" name="act" value="bargain">
        <input type="hidden" name="op" value="index">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label for="search_title"> 活动标题</label></th>
                <td><input type="text" name="search_title" value="<?php echo $output['search']['search_title']; ?>" id="search_title" class="txt"></td>
                <th><label>活动类型</label></th>
                <td>
                    <select name="search_state">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <option value="1" <?php echo $output['search']['search_state'] === '1' ? 'selected' : ''; ?>><?php echo '到店消费';?></option>
                        <option value="0" <?php echo $output['search']['search_state'] === '0' ? 'selected' : ''; ?>><?php echo '物流发货';?></option>
                    </select>
                </td>
                <th><label>所属商家</label></th>
                <td>
                    <select name="search_merchant">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['merchants'])): ?>
                            <?php foreach ($output['merchants'] as $k => $v): ?>
                                <option value="<?php echo $v['merchant_id']; ?>" <?php echo $output['search']['search_merchant'] == $v['merchant_id'] ? 'selected' : ''; ?>><?php echo $v['mc_shop_name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th></th>
                <td><a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search"></a></td>
            </tr>
            </tbody>
        </table>
    </form>
    <form method="post" id='form_advert'>
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2">
            <thead>
            <tr class="space">
                <th colspan="15" class="nobg"><?php echo $lang['nc_list'];?></th>
            </tr>
            <tr class="thead">
                <th><?php echo $lang['nc_common_select'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_name'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_type'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_url'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_advert_image'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_state'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_type'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_addtime'];?></th>
                <th class="align-center"><?php echo $lang['advert_index_add_time'];?></th>
                <th class="align-center"><?php echo $lang['nc_handle'];?></th>
            </tr>
            </thead>
            <tbody>
            <?php if(!empty($output['bargin_list']) && is_array($output['bargin_list'])){ ?>
                <?php foreach($output['bargin_list'] as $k => $v){ ?>
                    <tr class="hover">
                        <td class="w24">
                            <input name="del_id[]" type="checkbox" value="<?php echo $v['bargain_id']; ?>" class="checkitem" onclick="javascript:chkRow(this);">
                        </td>
                        <td class="align-center"><?php echo $v['bg_title']; ?></td>
                        <td class="align-center"><?php echo $v['shop_name']; ?></td>
                        <td class="align-center" ><?php echo $v['bg_price'];?></td>
                        <td class="align-center" ><img src="<?php echo UPLOAD.'product/'.$v['bg_thumb'];?>" style="width: 160px;height: 80px;"></td>
                        <td class="align-center"><?php echo $v['if_show']==1?$lang['nc_common_enable']:$lang['nc_common_disable']?></td>
                        <td class="align-center"><?php echo $v['type']==1?$lang['advert_index_type_xiaofei']:$lang['advert_index_type_wuliu']?></td>
                        <td class="align-center"><?php echo date('Y-m-d H:i',$v['start_time']); ?>——<?php echo date('Y-m-d H:i',$v['end_time']); ?></td>
                        <td class="align-center"><?php echo date('Y-m-d H:is',$v['add_time']); ?></td>
                        <td class="w150 align-center">
                            <a href="javascript:void(0)" onclick="confirmAble(<?php echo $v['bargain_id']; ?>, <?php echo $v['if_show']==1?0:1; ?>);"><?php echo $v['if_show']==1?$lang['nc_common_disable']:$lang['nc_common_enable']?></a>
                            | <a href="javascript:void(0)" onclick="confirmDel(<?php echo $v['bargain_id']; ?>);"><?php echo $lang['nc_delete'];?></a>
                            | <a href="index.php?act=bargain&op=bargain_edit&bargain_id=<?php echo $v['bargain_id']; ?>"><?php echo $lang['nc_edit'];?></a>
                        </td>
                    </tr>
                <?php } ?>
            <?php }else { ?>
                <tr class="no_data">
                    <td colspan="10"><?php echo $lang['nc_no_record'];?></td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
            <?php if(!empty($output['bargin_list']) && is_array($output['bargin_list'])){ ?>
                <tr class="tfoot">
                    <td><input type="checkbox" class="checkall" id="checkallBottom" name="chkVal"></td>
                    <td colspan="16"><label for="checkallBottom"><?php echo $lang['nc_select_all']; ?></label>
                        &nbsp;&nbsp;<a href="JavaScript:void(0);" class="btn" onclick="confirmDelAll();"><span><?php echo $lang['nc_del'];?></span></a>
                        <div class="pagination"> <?php echo $output['page'];?> </div></td>
                </tr>
            <?php } ?>
            </tfoot>
        </table>
    </form>
</div>
<script>
    function confirmAble(id, if_show) {
        var text = if_show?'<?php echo $lang['nc_common_enable']; ?>':'<?php echo $lang['nc_common_disable']; ?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            location.href = 'index.php?act=bargain&op=bargain_if_show&bargain_id='+id+'&if_show='+if_show;
        });
    }5

    function confirmDel(id) {
        var text = '<?php echo $lang['nc_ensure_del'];?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            location.href = 'index.php?act=bargain&op=bargain_del&bargain_id='+id;
        });
    }

    function confirmDelAll() {
        var inputs = $('input[name="del_id[]"]:checked')
        var ids = [];
        inputs.each(function (i) {
            ids.push(this.value);
        });
        //校验选项是否为空
        if (ids.length < 1) {
            layer.alert('<?php echo $lang['nc_common_select']; ?>');
            return;
        }

        var text = '<?php echo $lang['nc_ensure_del'];?>';
        layer.confirm(text, {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $('#form_advert').submit();
        });
    }
</script>
